package com.redisMq.consumer;

import com.redisMq.consumer.controller.AbcDefMessageListener;
import com.redisMq.consumer.controller.WlxMessageListener;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@SpringBootApplication
public class RedisMqConsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(RedisMqConsumerApplication.class, args);
	}


	/**
	 * RedisMessageListenerContainer提供订阅消息的多路分发，这样多个订阅可以共享同一个Redis连接.
	 */
	@Bean
	RedisMessageListenerContainer redisContainer(RedisConnectionFactory connectionFactory) {
		RedisMessageListenerContainer container = new RedisMessageListenerContainer();
		container.setConnectionFactory(connectionFactory);
		container.addMessageListener(new WlxMessageListener(), new ChannelTopic("wlx"));
		container.addMessageListener(new AbcDefMessageListener(), new ChannelTopic("abc"));
		container.addMessageListener(new AbcDefMessageListener(), new ChannelTopic("def"));
		return container;
	}
}
